var postApp = angular.module('postApp', []);
    postApp.controller('PostCtrl', function ($scope, $http) {
        $scope.names = [{id:'grain',name:'粮油米面'},
        {id:'fruit',name:'水果蔬菜'},
        {id:'tree',name:'苗木花卉'},
        {id:'water',name:'畜牧水产'},
        {id:'machine',name:'农资农机'},
        ];
        $scope.formData = {};
        $scope.formData.selectName = 'grain';
        $http.get('/user?uid=' + '<%= user._id %>')
                .success(function(result){
                    $scope.rightData = result;
                });
        $scope.PostSub = function (isVaild) {
            if ( isVaild ) {
                //如果表单内容格式正确
                $http({
                    method: 'POST',
                    url: '/post',
                    data: $.param($scope.formData),
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                }).success(function (data) {
                    if (data === 'success') {
                        alert('发表成功!');
                        window.location = '/';
                    } else {
                        $('#errorInfo').removeClass('hide').text(data);
                    }
                })
            } else {
                alert('输入有误！');
            }
        }
    });